#!/usr/bin/perl -w

my $user = `whoami`;
my $date = `date "+%Y-%m-%d %H:%M:%S"`;
my $name = "python_script.py";
my @line;
$name = $ARGV[0] if $#ARGV >= 0;


push(@line, "#!/usr/bin/python3\n");
push(@line, "\n");
push(@line, "###############################################################\n");
push(@line, "## Name       : $name\n");
push(@line, "## Author     : $user");
push(@line, "## Time       : $date");
push(@line, "## Description:\n");
push(@line, "## \n");
push(@line, "## \n");
push(@line, "###############################################################\n");
push(@line, "\n");

push(@line, "import sys\n");
push(@line, "import os\n");
push(@line, "import re\n");
push(@line, "import argparse\n");
push(@line, "import math\n");
push(@line, "\n");

push(@line, "def input_args_proc():\n");
push(@line, "    parser = argparse.ArgumentParser(description=\"argparse info\")\n");
push(@line, "    parser.add_argument('-o', action='store_true', default=False, help='open this script')\n");
push(@line, "    result = parser.parse_args()\n");
push(@line, "    if result.o == True:\n");
push(@line, "        os.system(\"gvim %s\" % __file__)\n");
push(@line, "        sys.exit(0)\n");
push(@line, "\n");

push(@line, "def main():\n");
push(@line, "    print(\"%s is working\" % __file__)\n");
push(@line, "    input_args_proc()\n");
push(@line, "\n");

push(@line, "if __name__ == \"__main__\":\n");
push(@line, "    main()\n");

open FILE, "> $name";
print FILE @line;
close FILE;
system("chmod a+x  $name");
